home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / pbm / Part1 next >
Encoding:
Internet Message Format  |  1991-08-07  |  34.5 KB

  1. From: jef@webster.UUCP (Jef Poskanzer)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i083: pbm - Portable Bitmap programs, Part 1/4
  4. Message-ID: <8803292002.AA24558@webster.sybase.uucp>
  5. Date: 29 Mar 88 20:02:46 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 83
  9. Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>
  10. Archive-Name: pbm/Part1
  11.  
  12. #! /bin/sh
  13. # This is a shell archive, meaning:
  14. # 1. Remove everything above the #! /bin/sh line.
  15. # 2. Save the resulting text in a file.
  16. # 3. Execute the file with /bin/sh (not csh) to create the files:
  17. #    README
  18. #    FORMATS
  19. #    Makefile
  20. #    cbmtopbm.c
  21. #    cbmtopbm.man
  22. #    icontopbm.c
  23. #    icontopbm.man
  24. #    macptopbm.c
  25. #    macptopbm.man
  26. #    rasttopbm.c
  27. #    rasttopbm.man
  28. # This archive created: Mon Mar 28 17:20:38 1988
  29. # By:    Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
  30. export PATH; PATH=/bin:$PATH
  31. echo shar: extracting "'README'" '(2590 characters)'
  32. if test -f 'README'
  33. then
  34.     echo shar: will not over-write existing file "'README'"
  35. else
  36. sed 's/^X//' << \SHAR_EOF > 'README'
  37. X                       Portable Bitmap Toolkit
  38. X                       Distribution of 28mar88
  39. X                    Previous distribution 06mar88
  40. X
  41. X
  42. XIncluded are a number of programs for converting various bitmap formats
  43. Xto and from a portable format; plus some tools for manipulating the
  44. Xportable bitmaps.
  45. X
  46. X
  47. XFiles in this distribution:
  48. X
  49. X    README        this
  50. X    FORMATS        descriptions of the various bitmap formats
  51. X    Makefile        guess
  52. X
  53. X    cbmtopbm.c        convert from compact bitmap to portable bitmap
  54. X    icontopbm.c        convert from Sun icon to portable bitmap
  55. X    macptopbm.c        convert from Macintosh MacPaint to portable bitmap
  56. X    rasttopbm.c        convert from Sun raster to portable bitmap
  57. X    xbmtopbm.c        convert from X10 or X11 bitmap to portable bitmap
  58. X    xwdtopbm.c        convert from X11 window dump file to portable bitmap
  59. X    xxxtopbm.c        convert from UNKNOWN BITMAP to portable bitmap
  60. X
  61. X    pbmtocbm.c        convert from portable bitmap to compact bitmap
  62. X    pbmtoicon.c        convert from portable bitmap to Sun icon
  63. X    pbmtorast.c        convert from portable bitmap to Sun raster
  64. X    pbmtoxbm.c        convert from portable bitmap to X11 bitmap
  65. X    pbmtox10bm.c    convert from portable bitmap to X10 bitmap
  66. X    pbmtops.c        convert from portable bitmap to PostScript
  67. X    pbmtoptx.c        convert from portable bitmap to Printronix
  68. X    pbmtoascii.c    convert from portable bitmap to ASCII graphic form
  69. X
  70. X    pbminvert.c        invert a portable bitmap
  71. X    pbmcrop.c        crop a portable bitmap
  72. X    pbmcatlr.c        concatenate portable bitmaps left to right
  73. X    pbmcattb.c        concatenate portable bitmaps top to bottom
  74. X    pbmfliplr.c        flip a portable bitmap left for right
  75. X    pbmfliptb.c        flip a portable bitmap top for bottom
  76. X    pbmtrnspos.c    transpose a portable bitmap x for y
  77. X    pbmcut.c        cut a rectangle out of a portable bitmap
  78. X    pbmpaste.c        paste a rectangle into a portable bitmap
  79. X    pbmenlarge.c    enlarge a portable bitmap N times
  80. X    pbmmake.c        create a blank bitmap of a specified size
  81. X
  82. X    libpbm.c        a few utility routines
  83. X    pbm.h        header file for libpbm
  84. X    bmaliases        csh script to make aliases for converting formats
  85. X    *.man        manual entries for all of the tools
  86. X    bit_reverse.h    useful include file
  87. X
  88. X
  89. XUnpack the files, edit Makefile and change the options to suit,
  90. Xmake, and enjoy!  I've tested this stuff under 4.2 BSD, 4.3 BSD,
  91. Xand System V rel 2.  Nevertheless, I'm sure bugs remain.  Feedback
  92. Xis welcome - send bug reports, enhancements, checks, money orders,
  93. Xetc. to the addresses below.
  94. X
  95. X
  96. X    Jef Poskanzer
  97. X    jef@lbl-rtsg.arpa
  98. X    {ucbvax, lll-crg, sun!pacbell, apple, hplabs}!well!pokey
  99. X    sun!pacbell!sybase!jef
  100. SHAR_EOF
  101. if test 2590 -ne "`wc -c < 'README'`"
  102. then
  103.     echo shar: error transmitting "'README'" '(should have been 2590 characters)'
  104. fi
  105. fi # end of overwriting check
  106. echo shar: extracting "'FORMATS'" '(3173 characters)'
  107. if test -f 'FORMATS'
  108. then
  109.     echo shar: will not over-write existing file "'FORMATS'"
  110. else
  111. sed 's/^X//' << \SHAR_EOF > 'FORMATS'
  112. XThe portable bitmap format is a lowest common denominator.
  113. X
  114. XFormats currently supported are:
  115. X
  116. X    X11 and X10 bitmaps
  117. X    X11 window dump files
  118. X    Sun icons
  119. X    Sun raster files.
  120. X    Macintosh MacPaint files
  121. X    PostScript
  122. X    Printronix printer graphics
  123. X    "portable bitmap format"
  124. X    "compact bitmap format"
  125. X
  126. X
  127. XThe portable bitmap format is something I came up with while I was
  128. Xat Xerox.  It is a lowest common denominator.  It was originally
  129. Xdesigned to make it reasonable to mail bitmaps between different
  130. Xtypes of machines using the typical stupid network mailers we have
  131. Xtoday.  Now it serves as the common language for this family of
  132. Xbitmap conversion filters.  The definition is as follows:
  133. X
  134. X    - A width, formatted as ASCII characters in decimal.
  135. X
  136. X    - Whitespace (blanks, TABs, CRs, LFs).
  137. X
  138. X    - A height, again in ASCII decimal.
  139. X
  140. X    - Whitespace.
  141. X
  142. X    - Width * height bits, each either '1' or '0', starting at the top-left
  143. X    corner of the bitmap, proceding in normal English reading order.
  144. X
  145. X    - The character '1' means black, '0' means white.
  146. X
  147. X    - Whitespace in the bits section is ignored.
  148. X
  149. X    - Characters from a "#" to the next end-of-line are ignored (comments).
  150. X
  151. X    - No line may be longer than 70 characters.
  152. X
  153. XHere is an example of a small bitmap in this format:
  154. X
  155. X    # feep.pbm
  156. X    24 7
  157. X    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  158. X    0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
  159. X    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
  160. X    0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
  161. X    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
  162. X    0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
  163. X    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  164. X
  165. XPrograms that read this format should be as lenient as possible,
  166. Xaccepting anything that looks remotely like a bitmap.  For instance,
  167. Xthe above example does not actually conform to the standard, since
  168. Xit has whitespace before the width; neverthless, it should be accepted.
  169. X
  170. X
  171. XThe compact bitmap format is the same basic idea as the portable
  172. Xformat, but it assumes the underlying filesystem can reliably store
  173. X8-bit bytes.  If you have the compress and zcat programs, you should
  174. Xnot bother with compact bitmaps -- all formats are about the same size
  175. Xafter being compressed.  Otherwise, compact bitmaps are probably the
  176. Xmost space-efficient format.  The definition:
  177. X
  178. X    - Two bytes of "magic number", which are always 0x2A 0x17.
  179. X
  180. X    - Two bytes representing the width.  The bytes are in "big-endian"
  181. X    order, i.e. the formula for the width is firstbyte * 256 + secondbyte.
  182. X
  183. X    - Two bytes representing the height, same order as above.
  184. X
  185. X    - The bits, in the same order as in the portable format: starting
  186. X    at the top-left, proceeding in normal English reading order.
  187. X    Within each byte, the most significant bit is used first, and so
  188. X    on down to the least significant bit.
  189. X
  190. X    - Nothing special happens at the end of a row -- no padding, not even
  191. X    to the end of the current byte.
  192. X    
  193. X    - A 1 bit means black, a 0 bit means white;
  194. X
  195. X    - All eight bits of each byte are used, except of course for the
  196. X    last byte, where there may be some extra bits.  These are ignored.
  197. SHAR_EOF
  198. if test 3173 -ne "`wc -c < 'FORMATS'`"
  199. then
  200.     echo shar: error transmitting "'FORMATS'" '(should have been 3173 characters)'
  201. fi
  202. fi # end of overwriting check
  203. echo shar: extracting "'Makefile'" '(6287 characters)'
  204. if test -f 'Makefile'
  205. then
  206.     echo shar: will not over-write existing file "'Makefile'"
  207. else
  208. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  209. X# Makefile for pbm tools.
  210. X#
  211. X# Copyright (C) 1988 by Jef Poskanzer.
  212. X#
  213. X# Permission to use, copy, modify, and distribute this software and its
  214. X# documentation for any purpose and without fee is hereby granted, provided
  215. X# that the above copyright notice appear in all copies and that both that
  216. X# copyright notice and this permission notice appear in supporting
  217. X# documentation.  This software is provided "as is" without express or
  218. X# implied warranty.
  219. X
  220. X
  221. X# Valid options:
  222. X#   OS_BSD      Set this if your system is BSD 4.2 or later.
  223. X#   OS_SYSV     Set this if your system is System V.
  224. XOPTIONS    =    -DOS_BSD
  225. X
  226. X
  227. XCC      =    cc
  228. XCFLAGS  =    -O $(OPTIONS)
  229. X
  230. X.SUFFIXES:    .man .cat
  231. X.man.cat:
  232. X        nroff -h -man $< > $@
  233. X
  234. X
  235. Xall:        cbmtopbm cbmtopbm.cat icontopbm icontopbm.cat macptopbm \
  236. X        macptopbm.cat rasttopbm rasttopbm.cat xbmtopbm \
  237. X        xbmtopbm.cat xwdtopbm xwdtopbm.cat pbmtocbm pbmtocbm.cat \
  238. X        pbmtoicon pbmtoicon.cat pbmtops pbmtops.cat pbmtoptx \
  239. X        pbmtoptx.cat pbmtorast pbmtorast.cat pbmtoxbm pbmtoxbm.cat \
  240. X        pbmtox10bm pbmtox10bm.cat pbmtoascii pbmtoascii.cat pbmcatlr \
  241. X        pbmcatlr.cat pbmcattb pbmcattb.cat pbmfliplr pbmfliplr.cat \
  242. X        pbmfliptb pbmfliptb.cat pbminvert pbminvert.cat pbmcrop \
  243. X        pbmcrop.cat pbmtrnspos pbmtrnspos.cat pbmcut pbmcut.cat \
  244. X        pbmpaste pbmpaste.cat xxxtopbm xxxtopbm.cat pbmenlarge \
  245. X        pbmenlarge.cat pbmmake pbmmake.cat pbm.cat
  246. X
  247. X
  248. Xcbmtopbm:    cbmtopbm.o libpbm.a
  249. X        $(CC) -s -o cbmtopbm cbmtopbm.o libpbm.a
  250. X
  251. Xcbmtopbm.o:    cbmtopbm.c pbm.h
  252. X
  253. X
  254. Xicontopbm:    icontopbm.o libpbm.a
  255. X        $(CC) -s -o icontopbm icontopbm.o libpbm.a
  256. X
  257. Xicontopbm.o:    icontopbm.c pbm.h
  258. X
  259. X
  260. Xmacptopbm:    macptopbm.o libpbm.a
  261. X        $(CC) -s -o macptopbm macptopbm.o libpbm.a
  262. X
  263. Xmacptopbm.o:    macptopbm.c pbm.h
  264. X
  265. X
  266. Xrasttopbm:    rasttopbm.o libpbm.a
  267. X        $(CC) -s -o rasttopbm rasttopbm.o libpbm.a -lpixrect
  268. X
  269. Xrasttopbm.o:    rasttopbm.c pbm.h
  270. X
  271. X
  272. Xxxxtopbm:    xxxtopbm.o libpbm.a
  273. X        $(CC) -s -o xxxtopbm xxxtopbm.o libpbm.a
  274. X
  275. Xxxxtopbm.o:    xxxtopbm.c pbm.h
  276. X
  277. X
  278. Xpbmcatlr:    pbmcatlr.o libpbm.a
  279. X        $(CC) -s -o pbmcatlr pbmcatlr.o libpbm.a
  280. X
  281. Xpbmcatlr.o:    pbmcatlr.c pbm.h
  282. X
  283. X
  284. Xpbmcattb:    pbmcattb.o libpbm.a
  285. X        $(CC) -s -o pbmcattb pbmcattb.o libpbm.a
  286. X
  287. Xpbmcattb.o:    pbmcattb.c pbm.h
  288. X
  289. X
  290. Xpbmfliplr:    pbmfliplr.o libpbm.a
  291. X        $(CC) -s -o pbmfliplr pbmfliplr.o libpbm.a
  292. X
  293. Xpbmfliplr.o:    pbmfliplr.c pbm.h
  294. X
  295. X
  296. Xpbmfliptb:    pbmfliptb.o libpbm.a
  297. X        $(CC) -s -o pbmfliptb pbmfliptb.o libpbm.a
  298. X
  299. Xpbmfliptb.o:    pbmfliptb.c pbm.h
  300. X
  301. X
  302. Xpbminvert:    pbminvert.o libpbm.a
  303. X        $(CC) -s -o pbminvert pbminvert.o libpbm.a
  304. X
  305. Xpbminvert.o:    pbminvert.c pbm.h
  306. X
  307. X
  308. Xpbmcrop:    pbmcrop.o libpbm.a
  309. X        $(CC) -s -o pbmcrop pbmcrop.o libpbm.a
  310. X
  311. Xpbmcrop.o:    pbmcrop.c pbm.h
  312. X
  313. X
  314. Xpbmtrnspos:    pbmtrnspos.o libpbm.a
  315. X        $(CC) -s -o pbmtrnspos pbmtrnspos.o libpbm.a
  316. X
  317. Xpbmtrnspos.o:    pbmtrnspos.c pbm.h
  318. X
  319. X
  320. Xpbmcut:        pbmcut.o libpbm.a
  321. X        $(CC) -s -o pbmcut pbmcut.o libpbm.a
  322. X
  323. Xpbmcut.o:    pbmcut.c pbm.h
  324. X
  325. X
  326. Xpbmpaste:    pbmpaste.o libpbm.a
  327. X        $(CC) -s -o pbmpaste pbmpaste.o libpbm.a
  328. X
  329. Xpbmpaste.o:    pbmpaste.c pbm.h
  330. X
  331. X
  332. Xpbmenlarge:    pbmenlarge.o libpbm.a
  333. X        $(CC) -s -o pbmenlarge pbmenlarge.o libpbm.a
  334. X
  335. Xpbmenlarge.o:    pbmenlarge.c pbm.h
  336. X
  337. X
  338. Xpbmmake:    pbmmake.o libpbm.a
  339. X        $(CC) -s -o pbmmake pbmmake.o libpbm.a
  340. X
  341. Xpbmmake.o:    pbmmake.c pbm.h
  342. X
  343. X
  344. Xpbmtocbm:    pbmtocbm.o libpbm.a
  345. X        $(CC) -s -o pbmtocbm pbmtocbm.o libpbm.a
  346. X
  347. Xpbmtocbm.o:    pbmtocbm.c pbm.h
  348. X
  349. X
  350. Xpbmtoicon:    pbmtoicon.o libpbm.a
  351. X        $(CC) -s -o pbmtoicon pbmtoicon.o libpbm.a
  352. X
  353. Xpbmtoicon.o:    pbmtoicon.c pbm.h
  354. X
  355. X
  356. Xpbmtops:    pbmtops.o libpbm.a
  357. X        $(CC) -s -o pbmtops pbmtops.o libpbm.a
  358. X
  359. Xpbmtops.o:    pbmtops.c pbm.h
  360. X
  361. X
  362. Xpbmtoptx:    pbmtoptx.o libpbm.a
  363. X        $(CC) -s -o pbmtoptx pbmtoptx.o libpbm.a
  364. X
  365. Xpbmtoptx.o:    pbmtoptx.c pbm.h
  366. X
  367. X
  368. Xpbmtorast:    pbmtorast.o libpbm.a
  369. X        $(CC) -s -o pbmtorast pbmtorast.o libpbm.a -lpixrect
  370. X
  371. Xpbmtorast.o:    pbmtorast.c pbm.h
  372. X
  373. X
  374. Xpbmtoxbm:    pbmtoxbm.o libpbm.a
  375. X        $(CC) -s -o pbmtoxbm pbmtoxbm.o libpbm.a
  376. X
  377. Xpbmtoxbm.o:    pbmtoxbm.c pbm.h
  378. X
  379. X
  380. Xpbmtox10bm:    pbmtox10bm.o libpbm.a
  381. X        $(CC) -s -o pbmtox10bm pbmtox10bm.o libpbm.a
  382. X
  383. Xpbmtox10bm.o:    pbmtox10bm.c pbm.h
  384. X
  385. X
  386. Xpbmtoascii:    pbmtoascii.o libpbm.a
  387. X        $(CC) -s -o pbmtoascii pbmtoascii.o libpbm.a
  388. X
  389. Xpbmtoascii.o:    pbmtoascii.c pbm.h
  390. X
  391. X
  392. Xxbmtopbm:    xbmtopbm.o libpbm.a
  393. X        $(CC) -s -o xbmtopbm xbmtopbm.o libpbm.a
  394. X
  395. Xxbmtopbm.o:    xbmtopbm.c pbm.h
  396. X
  397. X
  398. Xxwdtopbm:    xwdtopbm.o libpbm.a
  399. X        $(CC) -s -o xwdtopbm xwdtopbm.o libpbm.a
  400. X
  401. Xxwdtopbm.o:    xwdtopbm.c pbm.h
  402. X
  403. X
  404. Xlibpbm.a:    libpbm.o
  405. X        ar r libpbm.a libpbm.o
  406. X        -ranlib libpbm.a
  407. X
  408. Xlibpbm.o:    libpbm.c pbm.h
  409. X
  410. X
  411. Xclean:
  412. X        -rm -f *.o libpbm.a *.cat pbm.shar* core icontopbm
  413. X        -rm -f macptopbm rasttopbm pbmcatlr pbmcattb pbmcrop
  414. X        -rm -f pbmfliplr pbmfliptb pbminvert pbmtoicon pbmtops
  415. X        -rm -f pvmtoptx pbmtorast pbmtoxbm pbmtox10bm xbmtopbm
  416. X        -rm -f xwdtopbm pbmtoascii pbmtocbm cbmtopbm pbmtrnspos
  417. X        -rm -f pbmcut pbmpaste pbmenlarge pbmmake xxxtopbm
  418. X
  419. X
  420. Xshar:        pbm.shar1 pbm.shar2 pbm.shar3 pbm.shar4
  421. X
  422. Xpbm.shar1:    README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c \
  423. X        icontopbm.man macptopbm.c macptopbm.man rasttopbm.c \
  424. X        rasttopbm.man
  425. X        shar -v -c -p X README FORMATS Makefile cbmtopbm.c cbmtopbm.man icontopbm.c icontopbm.man macptopbm.c macptopbm.man rasttopbm.c rasttopbm.man > pbm.shar1
  426. X
  427. Xpbm.shar2:    xbmtopbm.c xbmtopbm.man xwdtopbm.c xwdtopbm.man pbmtocbm.c \
  428. X        pbmtocbm.man pbmtoicon.c pbmtoicon.man pbmtops.c pbmtops.man \
  429. X        pbmtoptx.c pbmtoptx.man pbmtorast.c pbmtorast.man
  430. X        shar -v -c -p X xbmtopbm.c xbmtopbm.man xwdtopbm.c xwdtopbm.man pbmtocbm.c pbmtocbm.man pbmtoicon.c pbmtoicon.man pbmtops.c pbmtops.man pbmtoptx.c pbmtoptx.man pbmtorast.c pbmtorast.man > pbm.shar2
  431. X
  432. Xpbm.shar3:    pbmtoxbm.c pbmtoxbm.man pbmtox10bm.c pbmtox10bm.man \
  433. X        pbmtoascii.c pbmtoascii.man pbmcatlr.c pbmcatlr.man pbmcattb.c \
  434. X        pbmcattb.man pbmfliplr.c pbmfliplr.man pbmfliptb.c \
  435. X        pbmfliptb.man pbminvert.c pbminvert.man
  436. X        shar -v -c -p X pbmtoxbm.c pbmtoxbm.man pbmtox10bm.c pbmtox10bm.man pbmtoascii.c pbmtoascii.man pbmcatlr.c pbmcatlr.man pbmcattb.c pbmcattb.man pbmfliplr.c pbmfliplr.man pbmfliptb.c pbmfliptb.man pbminvert.c pbminvert.man > pbm.shar3
  437. X
  438. Xpbm.shar4:    pbmcrop.c pbmcrop.man pbmtrnspos.c pbmtrnspos.man pbmcut.c \
  439. X        pbmcut.man pbmpaste.c pbmpaste.man xxxtopbm.c xxxtopbm.man \
  440. X        pbmenlarge.c pbmenlarge.man pbmmake.c pbmmake.man libpbm.c \
  441. X        pbm.h pbm.man bmaliases bit_reverse.h
  442. X        shar -v -c -p X pbmcrop.c pbmcrop.man pbmtrnspos.c pbmtrnspos.man pbmcut.c pbmcut.man pbmpaste.c pbmpaste.man xxxtopbm.c xxxtopbm.man pbmenlarge.c pbmenlarge.man pbmmake.c pbmmake.man libpbm.c pbm.h pbm.man bmaliases bit_reverse.h > pbm.shar4
  443. SHAR_EOF
  444. if test 6287 -ne "`wc -c < 'Makefile'`"
  445. then
  446.     echo shar: error transmitting "'Makefile'" '(should have been 6287 characters)'
  447. fi
  448. fi # end of overwriting check
  449. echo shar: extracting "'cbmtopbm.c'" '(1923 characters)'
  450. if test -f 'cbmtopbm.c'
  451. then
  452.     echo shar: will not over-write existing file "'cbmtopbm.c'"
  453. else
  454. sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.c'
  455. X/* cbmtopbm.c - read a compact bitmap and write a portable bitmap
  456. X**
  457. X** Copyright (C) 1988 by Jef Poskanzer.
  458. X**
  459. X** Permission to use, copy, modify, and distribute this software and its
  460. X** documentation for any purpose and without fee is hereby granted, provided
  461. X** that the above copyright notice appear in all copies and that both that
  462. X** copyright notice and this permission notice appear in supporting
  463. X** documentation.  This software is provided "as is" without express or
  464. X** implied warranty.
  465. X*/
  466. X
  467. X#include <stdio.h>
  468. X#include "pbm.h"
  469. X
  470. Xmain( argc, argv )
  471. Xint argc;
  472. Xchar *argv[];
  473. X    {
  474. X    FILE *ifd;
  475. X    bit **bits, getbit();
  476. X    int rows, cols, row, col;
  477. X
  478. X    if ( argc > 2 )
  479. X    {
  480. X    fprintf( stderr, "usage:  %s [cbmfile]\n", argv[0] );
  481. X    exit( 1 );
  482. X    }
  483. X
  484. X    if ( argc == 2 )
  485. X    {
  486. X        ifd = fopen( argv[1], "r" );
  487. X        if ( ifd == NULL )
  488. X        {
  489. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  490. X        exit( 1 );
  491. X        }
  492. X    }
  493. X    else
  494. X    ifd = stdin;
  495. X
  496. X    getinit( ifd, &cols, &rows );
  497. X
  498. X    bits = pbm_allocarray( cols, rows );
  499. X
  500. X    for ( row = 0; row < rows; row++ )
  501. X        for ( col = 0; col < cols; col++ )
  502. X        bits[row][col] = getbit( ifd );
  503. X
  504. X    if ( ifd != stdin )
  505. X    fclose( ifd );
  506. X    
  507. X    pbm_writepbm( stdout, bits, cols, rows );
  508. X
  509. X    exit( 0 );
  510. X    }
  511. X
  512. X
  513. Xint item, bitsperitem, bitshift;
  514. X
  515. Xgetinit( file, colp, rowp )
  516. XFILE *file;
  517. Xint *colp, *rowp;
  518. X    {
  519. X    if ( getc( file ) != 42 )
  520. X    {
  521. X    fprintf( stderr, "Bad magic number 1.\n" );
  522. X    exit( 1 );
  523. X    }
  524. X    if ( getc( file ) != 23 )
  525. X    {
  526. X    fprintf( stderr, "Bad magic number 2.\n" );
  527. X    exit( 1 );
  528. X    }
  529. X    *colp = getc( file ) << 8;
  530. X    *colp += getc( file );
  531. X    *rowp = getc( file ) << 8;
  532. X    *rowp += getc( file );
  533. X    bitsperitem = 8;
  534. X    }
  535. X
  536. Xbit
  537. Xgetbit( file )
  538. XFILE *file;
  539. X    {
  540. X    bit b;
  541. X
  542. X    if ( bitsperitem == 8 )
  543. X    {
  544. X    item = getc( file );
  545. X    bitsperitem = 0;
  546. X    bitshift = 7;
  547. X    }
  548. X    bitsperitem++;
  549. X    b = ( item >> bitshift) & 1;
  550. X    bitshift--;
  551. X    return ( b );
  552. X    }
  553. SHAR_EOF
  554. if test 1923 -ne "`wc -c < 'cbmtopbm.c'`"
  555. then
  556.     echo shar: error transmitting "'cbmtopbm.c'" '(should have been 1923 characters)'
  557. fi
  558. fi # end of overwriting check
  559. echo shar: extracting "'cbmtopbm.man'" '(969 characters)'
  560. if test -f 'cbmtopbm.man'
  561. then
  562.     echo shar: will not over-write existing file "'cbmtopbm.man'"
  563. else
  564. sed 's/^X//' << \SHAR_EOF > 'cbmtopbm.man'
  565. X.TH cbmtopbm 1 "13 February 1988"
  566. X.SH NAME
  567. Xcbmtopbm - convert compact bitmaps into portable bitmaps
  568. X.SH SYNOPSIS
  569. Xcbmtopbm [cbmfile]
  570. X.SH DESCRIPTION
  571. XReads a compact bitmap as input.
  572. XProduces a portable bitmap as output.
  573. X.SH "SEE ALSO"
  574. Xpbm(5), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  575. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  576. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  577. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  578. Xpbmpaste(1), pbmenlarge(1)
  579. X.SH AUTHOR
  580. XCopyright (C) 1988 by Jef Poskanzer.
  581. X
  582. XPermission to use, copy, modify, and distribute this software and its
  583. Xdocumentation for any purpose and without fee is hereby granted, provided
  584. Xthat the above copyright notice appear in all copies and that both that
  585. Xcopyright notice and this permission notice appear in supporting
  586. Xdocumentation.  This software is provided "as is" without express or
  587. Ximplied warranty.
  588. SHAR_EOF
  589. if test 969 -ne "`wc -c < 'cbmtopbm.man'`"
  590. then
  591.     echo shar: error transmitting "'cbmtopbm.man'" '(should have been 969 characters)'
  592. fi
  593. fi # end of overwriting check
  594. echo shar: extracting "'icontopbm.c'" '(4272 characters)'
  595. if test -f 'icontopbm.c'
  596. then
  597.     echo shar: will not over-write existing file "'icontopbm.c'"
  598. else
  599. sed 's/^X//' << \SHAR_EOF > 'icontopbm.c'
  600. X/* icontopbm.c - read a Sun icon file and produce a portable bitmap
  601. X**
  602. X** Copyright (C) 1988 by Jef Poskanzer.
  603. X**
  604. X** Permission to use, copy, modify, and distribute this software and its
  605. X** documentation for any purpose and without fee is hereby granted, provided
  606. X** that the above copyright notice appear in all copies and that both that
  607. X** copyright notice and this permission notice appear in supporting
  608. X** documentation.  This software is provided "as is" without express or
  609. X** implied warranty.
  610. X*/
  611. X
  612. X#include <stdio.h>
  613. X#include <sys/types.h>
  614. X#include "pbm.h"
  615. X
  616. Xmain( argc, argv )
  617. Xint argc;
  618. Xchar *argv[];
  619. X    {
  620. X    FILE *ifd;
  621. X    bit **bits;
  622. X    int rows, cols, row, col, shortcount, mask;
  623. X    short *data;
  624. X
  625. X    if ( argc > 2 )
  626. X    {
  627. X    fprintf( stderr, "usage: %s [iconfile]\n", argv[0] );
  628. X    exit( 1 );
  629. X    }
  630. X
  631. X    if ( argc == 2 )
  632. X    {
  633. X    ifd = fopen( argv[1], "r" );
  634. X    if ( ifd == NULL )
  635. X        {
  636. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  637. X        exit( 1 );
  638. X        }
  639. X    }
  640. X    else
  641. X    ifd = stdin;
  642. X
  643. X    if ( ReadIconFile( ifd, &cols, &rows, &data ) < 0 )
  644. X    {
  645. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  646. X    exit( 1 );
  647. X    }
  648. X
  649. X    if ( ifd != stdin )
  650. X    fclose( ifd );
  651. X
  652. X    bits = pbm_allocarray( cols, rows );
  653. X
  654. X    for ( row = 0; row < rows; row++ )
  655. X    {
  656. X    shortcount = 0;
  657. X    mask = 0x8000;
  658. X    for ( col = 0; col < cols; col++ )
  659. X        {
  660. X        if ( shortcount >= 16 )
  661. X        {
  662. X        data++;
  663. X        shortcount = 0;
  664. X        mask = 0x8000;
  665. X        }
  666. X        bits[row][col] = ( ( *data & mask ) ? 1 : 0 );
  667. X        shortcount++;
  668. X        mask = mask >> 1;
  669. X        }
  670. X    data++;
  671. X    }
  672. X
  673. X    pbm_writepbm( stdout, bits, cols, rows );
  674. X
  675. X    exit( 0 );
  676. X    }
  677. X
  678. X
  679. X/* size in bytes of a bitmap */
  680. X#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height))
  681. X
  682. Xint
  683. XReadIconFile( file, width, height, data )
  684. XFILE *file;
  685. Xint *width, *height;
  686. Xshort **data;
  687. X    {
  688. X    char variable[81], ch;
  689. X    int status, firsttime, value, i, data_length;
  690. X
  691. X    if ( file == NULL )
  692. X        return ( -1 );
  693. X
  694. X    if ( getc( file ) != '/' )
  695. X    {
  696. X    fprintf( stderr, "Error 1 scanning beginning of initial section.\n" );
  697. X    return ( -1 );
  698. X    }
  699. X    if ( getc( file ) != '*' )
  700. X    {
  701. X    fprintf( stderr, "Error 2 scanning beginning of initial section.\n" );
  702. X    return ( -1 );
  703. X    }
  704. X    while ( ( ch = getc( file ) ) == '\n' | ch == '\t' | ch == ' ' )
  705. X    ;
  706. X    ungetc( ch, stdin );
  707. X
  708. X    *width = *height = -1;
  709. X    firsttime = -1;
  710. X    for ( ; ; )
  711. X    {
  712. X    if ( firsttime )
  713. X        firsttime = 0;
  714. X    else
  715. X        if ( getc( file ) != ',' )
  716. X        break;
  717. X    while ( ( ch = getc( file ) ) == '\n' | ch == '\t' | ch == ' ' )
  718. X        ;
  719. X    for ( i = 0; ch != '='; i++ )
  720. X        {
  721. X        variable[i] = ch;
  722. X        ch = getc( file );
  723. X        }
  724. X    variable[i] = '\0';
  725. X
  726. X    if ( fscanf( file, "%d", &value ) != 1 )
  727. X        break;
  728. X
  729. X    if ( strcmp( variable, "Width" ) == 0 )
  730. X        *width = value;
  731. X    else if ( strcmp( variable, "Height" ) == 0 )
  732. X            *height = value;
  733. X    else if ( strcmp( variable, "Depth" ) == 0 )
  734. X            {
  735. X        if ( value != 1 )
  736. X        {
  737. X        fprintf( stderr, "Invalid depth.\n" );
  738. X        return ( -1 );
  739. X        }
  740. X        }
  741. X    else if ( strcmp( variable, "Format_version" ) == 0 )
  742. X            {
  743. X        if ( value != 1 )
  744. X        {
  745. X        fprintf( stderr, "Invalid Format_version.\n" );
  746. X        return ( -1 );
  747. X        }
  748. X        }
  749. X    else if ( strcmp( variable, "Valid_bits_per_item" ) == 0 )
  750. X            {
  751. X        if ( value != 16 )
  752. X        {
  753. X        fprintf( stderr, "Invalid Valid_bits_per_item.\n" );
  754. X        return ( -1 );
  755. X        }
  756. X        }
  757. X    }
  758. X
  759. X    for ( ; ; )
  760. X    {
  761. X    while ( getc( file ) != '*' )
  762. X        ;
  763. X    if ( ( ch = getc( file ) ) == '/' )
  764. X        break;
  765. X    ungetc( ch, stdin );
  766. X    }
  767. X    if ( getc( file ) != '\n' )
  768. X    {
  769. X    fprintf( stderr, "Error 3 scanning end of initial section.\n" );
  770. X    return ( -1 );
  771. X    }
  772. X
  773. X    if ( *width <= 0 )
  774. X    {
  775. X    fprintf( stderr, "Invalid width: %d.\n", *width );
  776. X    return ( -1 );
  777. X    }
  778. X    
  779. X    if ( *height <= 0 )
  780. X    {
  781. X    fprintf( stderr, "Invalid height: %d.\n", *height );
  782. X    return ( -1 );
  783. X    }
  784. X
  785. X    data_length = BitmapSize( *width, *height );
  786. X    *data = (short *) malloc( data_length );
  787. X    data_length /= sizeof( short );
  788. X    if ( *data == NULL )
  789. X        {
  790. X        return ( -1 );
  791. X    }
  792. X    
  793. X    for ( i = 0 ; i < data_length; i++ )
  794. X    {
  795. X    if ( i == 0 )
  796. X        status = fscanf( file, " 0x%4hx", *data );
  797. X    else
  798. X        status = fscanf( file, ", 0x%4hx", *data + i );
  799. X    if ( status != 1 )
  800. X        {
  801. X        free( *data );
  802. X        fprintf( stderr, "Error 4 scanning bits item.\n" );
  803. X        return ( -1 );
  804. X        }
  805. X        }
  806. X
  807. X    return ( 0 );
  808. X    }
  809. SHAR_EOF
  810. if test 4272 -ne "`wc -c < 'icontopbm.c'`"
  811. then
  812.     echo shar: error transmitting "'icontopbm.c'" '(should have been 4272 characters)'
  813. fi
  814. fi # end of overwriting check
  815. echo shar: extracting "'icontopbm.man'" '(960 characters)'
  816. if test -f 'icontopbm.man'
  817. then
  818.     echo shar: will not over-write existing file "'icontopbm.man'"
  819. else
  820. sed 's/^X//' << \SHAR_EOF > 'icontopbm.man'
  821. X.TH icontopbm 1 "13 February 1988"
  822. X.SH NAME
  823. Xicontopbm - convert Sun icons into portable bitmaps
  824. X.SH SYNOPSIS
  825. Xicontopbm [iconfile]
  826. X.SH DESCRIPTION
  827. XReads a Sun icon as input.
  828. XProduces a portable bitmap as output.
  829. X.SH "SEE ALSO"
  830. Xpbm(5), cbmtopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  831. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  832. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  833. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  834. Xpbmpaste(1), pbmenlarge(1)
  835. X.SH AUTHOR
  836. XCopyright (C) 1988 by Jef Poskanzer.
  837. X
  838. XPermission to use, copy, modify, and distribute this software and its
  839. Xdocumentation for any purpose and without fee is hereby granted, provided
  840. Xthat the above copyright notice appear in all copies and that both that
  841. Xcopyright notice and this permission notice appear in supporting
  842. Xdocumentation.  This software is provided "as is" without express or
  843. Ximplied warranty.
  844. SHAR_EOF
  845. if test 960 -ne "`wc -c < 'icontopbm.man'`"
  846. then
  847.     echo shar: error transmitting "'icontopbm.man'" '(should have been 960 characters)'
  848. fi
  849. fi # end of overwriting check
  850. echo shar: extracting "'macptopbm.c'" '(3073 characters)'
  851. if test -f 'macptopbm.c'
  852. then
  853.     echo shar: will not over-write existing file "'macptopbm.c'"
  854. else
  855. sed 's/^X//' << \SHAR_EOF > 'macptopbm.c'
  856. X/* macptopbm.c - read a Macintosh MacPaint file and produce a portable bitmap
  857. X**
  858. X** Copyright (C) 1988 by Jef Poskanzer.
  859. X**
  860. X** Permission to use, copy, modify, and distribute this software and its
  861. X** documentation for any purpose and without fee is hereby granted, provided
  862. X** that the above copyright notice appear in all copies and that both that
  863. X** copyright notice and this permission notice appear in supporting
  864. X** documentation.  This software is provided "as is" without express or
  865. X** implied warranty.
  866. X*/
  867. X
  868. X#include <stdio.h>
  869. X#include <sys/types.h>
  870. X#include "pbm.h"
  871. X
  872. X#define    BORDER_WIDTH    3
  873. X#define    HEADER_LENGTH    0x280
  874. X#define    MAX_LINES    720
  875. X#define    BYTES_WIDE    72
  876. X#define    MAX_NAME    64
  877. X
  878. Xmain( argc, argv )
  879. Xint argc;
  880. Xchar *argv[];
  881. X    {
  882. X    FILE *ifd;
  883. X    unsigned char Pic[MAX_LINES][BYTES_WIDE];
  884. X    bit **bits;
  885. X    int scanLine, rows, cols, row, bcol, i;
  886. X
  887. X    if ( argc > 2 )
  888. X    {
  889. X    fprintf( stderr, "usage: %s [macpfile]\n", argv[0] );
  890. X    exit( 1 );
  891. X    }
  892. X
  893. X    if ( argc == 2 )
  894. X    {
  895. X    ifd = fopen( argv[1], "r" );
  896. X    if ( ifd == NULL )
  897. X        {
  898. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  899. X        exit( 1 );
  900. X        }
  901. X    }
  902. X    else
  903. X    ifd = stdin;
  904. X
  905. X    if ( ReadMacPaintFile( ifd, &scanLine, Pic ) < 0 )
  906. X    {
  907. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  908. X    exit( 1 );
  909. X    }
  910. X
  911. X    if ( ifd != stdin )
  912. X    fclose( ifd );
  913. X
  914. X    cols = BYTES_WIDE * 8;
  915. X    rows = scanLine;
  916. X    bits = pbm_allocarray( cols, rows );
  917. X
  918. X    for ( row = 0; row < rows; row++ )
  919. X    for ( bcol = 0; bcol < BYTES_WIDE; bcol++ )
  920. X        for ( i = 0; i < 8; i++ )
  921. X        bits[row][bcol * 8 + i] = ( (Pic[row][bcol] >> (7 - i)) & 1);
  922. X
  923. X    pbm_writepbm( stdout, bits, cols, rows );
  924. X
  925. X    exit( 0 );
  926. X    }
  927. X
  928. X/*
  929. X** Some of the following routine is:
  930. X**
  931. X**                Copyright 1987 by Patrick J. Naughton
  932. X**                         All Rights Reserved
  933. X** Permission to use, copy, modify, and distribute this software and its
  934. X** documentation for any purpose and without fee is hereby granted,
  935. X** provided that the above copyright notice appear in all copies and that
  936. X** both that copyright notice and this permission notice appear in
  937. X** supporting documentation.
  938. X*/
  939. X
  940. Xint
  941. XReadMacPaintFile( file, scanLineP, Pic )
  942. XFILE *file;
  943. Xint *scanLineP;
  944. Xunsigned char Pic[MAX_LINES][BYTES_WIDE];
  945. X    {
  946. X    unsigned int i, j, k;
  947. X    unsigned char ch;
  948. X
  949. X    /* Skip over the header. */
  950. X    for ( i = 0; i < HEADER_LENGTH; i++ )
  951. X    getc( file );
  952. X
  953. X    *scanLineP = 0;
  954. X    k = 0;
  955. X
  956. X    while ( *scanLineP < MAX_LINES )
  957. X    {
  958. X    ch = (unsigned char) getc( file );    /* Count byte */
  959. X    i = (unsigned int) ch;
  960. X    if ( ch < 0x80 )
  961. X        {    /* Unpack next (I+1) chars as is */
  962. X        for ( j = 0; j <= i; j++ )
  963. X        if ( *scanLineP < MAX_LINES )
  964. X            {
  965. X            Pic[*scanLineP][k++] = (unsigned char) getc( file );
  966. X            if ( ! (k %= BYTES_WIDE) )
  967. X            *scanLineP += 1;
  968. X            }
  969. X        }
  970. X    else
  971. X        {    /* Repeat next char (2's comp I) times */
  972. X        ch = getc( file );
  973. X        for ( j = 0; j <= 256 - i; j++ )
  974. X        if ( *scanLineP < MAX_LINES )
  975. X            {
  976. X            Pic[*scanLineP][k++] = (unsigned char) ch;
  977. X            if ( ! (k %= BYTES_WIDE) )
  978. X            *scanLineP += 1;
  979. X            }
  980. X        }
  981. X    }
  982. X
  983. X    return(0);
  984. X    }
  985. SHAR_EOF
  986. if test 3073 -ne "`wc -c < 'macptopbm.c'`"
  987. then
  988.     echo shar: error transmitting "'macptopbm.c'" '(should have been 3073 characters)'
  989. fi
  990. fi # end of overwriting check
  991. echo shar: extracting "'macptopbm.man'" '(1452 characters)'
  992. if test -f 'macptopbm.man'
  993. then
  994.     echo shar: will not over-write existing file "'macptopbm.man'"
  995. else
  996. sed 's/^X//' << \SHAR_EOF > 'macptopbm.man'
  997. X.TH macptopbm 1 "13 February 1988"
  998. X.SH NAME
  999. Xmacptopbm - convert Macintosh MacPaint files into portable bitmaps
  1000. X.SH SYNOPSIS
  1001. Xmacptopbm [macpfile]
  1002. X.SH DESCRIPTION
  1003. XReads a Macintosh MacPaint file as input.
  1004. XProduces a portable bitmap as output.
  1005. X.LP
  1006. XNote that there is currently no pbmtomacp tool.
  1007. X.SH "SEE ALSO"
  1008. Xpbm(5), cbmtopbm(1), icontopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1009. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  1010. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1011. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1012. Xpbmpaste(1), pbmenlarge(1)
  1013. X.SH AUTHOR
  1014. XCopyright (C) 1988 by Jef Poskanzer.
  1015. X
  1016. XPermission to use, copy, modify, and distribute this software and its
  1017. Xdocumentation for any purpose and without fee is hereby granted, provided
  1018. Xthat the above copyright notice appear in all copies and that both that
  1019. Xcopyright notice and this permission notice appear in supporting
  1020. Xdocumentation.  This software is provided "as is" without express or
  1021. Ximplied warranty.
  1022. X
  1023. XThe MacPaint-reading code is
  1024. X   Copyright (c) 1987 by Patrick J. Naughton,
  1025. X   (naughton@sun.soe.clarkson.edu)
  1026. X
  1027. X Permission to use, copy, modify, and distribute this software and its
  1028. Xdocumentation for any purpose and without fee is hereby granted,
  1029. Xprovided that the above copyright notice appear in all copies and that
  1030. Xboth that copyright notice and this permission notice appear in
  1031. Xsupporting documentation. 
  1032. SHAR_EOF
  1033. if test 1452 -ne "`wc -c < 'macptopbm.man'`"
  1034. then
  1035.     echo shar: error transmitting "'macptopbm.man'" '(should have been 1452 characters)'
  1036. fi
  1037. fi # end of overwriting check
  1038. echo shar: extracting "'rasttopbm.c'" '(3255 characters)'
  1039. if test -f 'rasttopbm.c'
  1040. then
  1041.     echo shar: will not over-write existing file "'rasttopbm.c'"
  1042. else
  1043. sed 's/^X//' << \SHAR_EOF > 'rasttopbm.c'
  1044. X/* rasttopbm.c - read a Sun raster file and produce a portable bitmap
  1045. X**
  1046. X** Copyright (C) 1988 by Jef Poskanzer.
  1047. X**
  1048. X** Permission to use, copy, modify, and distribute this software and its
  1049. X** documentation for any purpose and without fee is hereby granted, provided
  1050. X** that the above copyright notice appear in all copies and that both that
  1051. X** copyright notice and this permission notice appear in supporting
  1052. X** documentation.  This software is provided "as is" without express or
  1053. X** implied warranty.
  1054. X*/
  1055. X
  1056. X#include <stdio.h>
  1057. X#include "pbm.h"
  1058. X
  1059. X/* Because of the following include, this program compiles only on Suns. */
  1060. X#include <pixrect/pixrect_hs.h>
  1061. X
  1062. Xmain( argc, argv )
  1063. Xint argc;
  1064. Xchar *argv[];
  1065. X    {
  1066. X    FILE *ifd;
  1067. X    bit **bits;
  1068. X    int rows, cols, row, col, shortcount, mask;
  1069. X    int linesize;
  1070. X    short *data;
  1071. X
  1072. X    if ( argc > 2 )
  1073. X    {
  1074. X    fprintf( stderr, "usage: %s [rastfile]\n", argv[0] );
  1075. X    exit( 1 );
  1076. X    }
  1077. X
  1078. X    if ( argc == 2 )
  1079. X    {
  1080. X    ifd = fopen( argv[1], "r" );
  1081. X    if ( ifd == NULL )
  1082. X        {
  1083. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  1084. X        exit( 1 );
  1085. X        }
  1086. X    }
  1087. X    else
  1088. X    ifd = stdin;
  1089. X
  1090. X    if ( ReadRasterFile( ifd, &cols, &rows, &linesize, &data ) < 0 )
  1091. X    {
  1092. X    fprintf( stderr, "%s: can't load.\n", argv[1] );
  1093. X    exit( 1 );
  1094. X    }
  1095. X
  1096. X    if ( ifd != stdin )
  1097. X    fclose( ifd );
  1098. X
  1099. X    bits = pbm_allocarray( cols, rows );
  1100. X
  1101. X    for ( row = 0; row < rows; row++ )
  1102. X    {
  1103. X    shortcount = 0;
  1104. X    mask = 0x8000;
  1105. X    for ( col = 0; col < cols; col++ )
  1106. X        {
  1107. X        if ( mask == 0 )
  1108. X        {
  1109. X        shortcount++;
  1110. X        mask = 0x8000;
  1111. X        }
  1112. X        bits[row][col] = ( *(data + shortcount) & mask ) ? 1 : 0;
  1113. X        mask = mask >> 1;
  1114. X        }
  1115. X    data += linesize / sizeof(short);
  1116. X    }
  1117. X
  1118. X    pbm_writepbm( stdout, bits, cols, rows );
  1119. X
  1120. X    exit( 0 );
  1121. X    }
  1122. X
  1123. X
  1124. Xint
  1125. XReadRasterFile( file, width, height, linebytes, data )
  1126. XFILE *file;
  1127. Xint *width, *height;
  1128. Xint *linebytes;
  1129. Xshort **data;
  1130. X    {
  1131. X    struct rasterfile header;
  1132. X    struct pixrect *pr, *pr_load_image();
  1133. X    int status, firsttime, value, i, data_length;
  1134. X
  1135. X    if ( file == NULL )
  1136. X    return ( -1 );
  1137. X
  1138. X    *width = *height = -1;
  1139. X
  1140. X
  1141. X    /* Get the raster file's header. */
  1142. X    if ( pr_load_header( file, &header ) != 0 )
  1143. X    {
  1144. X    fprintf( stderr, "Unable to read in raster file header.\n");
  1145. X    return ( -1 );
  1146. X    }
  1147. X
  1148. X    /* PBM can only handle monochrome bitmaps. */
  1149. X    if ( header.ras_depth != 1 )
  1150. X    {
  1151. X    fprintf( stderr, "Invalid depth.\n" );
  1152. X    return ( -1 );
  1153. X    }
  1154. X
  1155. X    *width = header.ras_width;
  1156. X    *height = header.ras_height;
  1157. X    if ( *width <= 0 )
  1158. X    {
  1159. X    fprintf( stderr, "Invalid width: %d.\n", *width );
  1160. X    return ( -1 );
  1161. X    }
  1162. X    
  1163. X    if ( *height <= 0 )
  1164. X    {
  1165. X    fprintf( stderr, "Invalid height: %d.\n", *height );
  1166. X    return ( -1 );
  1167. X    }
  1168. X
  1169. X    /* If there is a color map, skip over it. */
  1170. X    if ( header.ras_maptype != RMT_NONE && header.ras_maplength != 0 )
  1171. X    {
  1172. X    if (pr_load_colormap(file, &header, NULL) != 0)
  1173. X        {
  1174. X        fprintf( stderr, "Unable to skip colormap data.\n");
  1175. X        return ( -1 );
  1176. X        }
  1177. X    }
  1178. X
  1179. X    /* Now load the data.  The pixrect returned is a memory pixrect. */
  1180. X    if ( (pr = pr_load_image(file, &header, NULL)) == NULL )
  1181. X    {
  1182. X    fprintf(
  1183. X        stderr, "Unable to read in the image from the raster file.\n");
  1184. X    return ( -1 );
  1185. X    }
  1186. X
  1187. X    *linebytes = ((struct mpr_data *)pr->pr_data)->md_linebytes;
  1188. X    *data = ((struct mpr_data *)pr->pr_data)->md_image;
  1189. X
  1190. X    return ( 0 );
  1191. X    }
  1192. SHAR_EOF
  1193. if test 3255 -ne "`wc -c < 'rasttopbm.c'`"
  1194. then
  1195.     echo shar: error transmitting "'rasttopbm.c'" '(should have been 3255 characters)'
  1196. fi
  1197. fi # end of overwriting check
  1198. echo shar: extracting "'rasttopbm.man'" '(1350 characters)'
  1199. if test -f 'rasttopbm.man'
  1200. then
  1201.     echo shar: will not over-write existing file "'rasttopbm.man'"
  1202. else
  1203. sed 's/^X//' << \SHAR_EOF > 'rasttopbm.man'
  1204. X.TH rasttopbm 1 "18 February 1988"
  1205. X.SH NAME
  1206. Xrasttopbm - convert Sun rasters into portable bitmaps
  1207. X.SH SYNOPSIS
  1208. Xrasttopbm [rastfile]
  1209. X.SH DESCRIPTION
  1210. XReads a Sun raster as input.
  1211. XProduces a portable bitmap as output.
  1212. XNOTE: since it uses Sun-specific include files, pbmtorast will compile
  1213. Xonly on Suns.
  1214. X.LP
  1215. XUsing this program you can convert anything you can see on a Sun screen
  1216. Xinto a pbm bitmap.
  1217. XJust display whatever you're interested in, do a screendump, run it through
  1218. Xrasfilter8to1 if you're on a color Sun, run it through rasttopbm, and then
  1219. Xuse pbmcut to select the part you want.
  1220. X.SH "SEE ALSO"
  1221. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), xbmtopbm(1), xwdtopbm(1),
  1222. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  1223. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1224. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1225. Xpbmpaste(1), pbmenlarge(1)
  1226. X.SH AUTHOR
  1227. XBarry Klawans
  1228. X
  1229. XCopyright (C) 1988 by Jef Poskanzer.
  1230. X
  1231. XPermission to use, copy, modify, and distribute this software and its
  1232. Xdocumentation for any purpose and without fee is hereby granted, provided
  1233. Xthat the above copyright notice appear in all copies and that both that
  1234. Xcopyright notice and this permission notice appear in supporting
  1235. Xdocumentation.  This software is provided "as is" without express or
  1236. Ximplied warranty.
  1237. SHAR_EOF
  1238. if test 1350 -ne "`wc -c < 'rasttopbm.man'`"
  1239. then
  1240.     echo shar: error transmitting "'rasttopbm.man'" '(should have been 1350 characters)'
  1241. fi
  1242. fi # end of overwriting check
  1243. #    End of shell archive
  1244. exit 0
  1245.